package com.lcq.study.javabase;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * @ClassName FunctionTest
 * @Description
 * @Author lichuanqi
 * @Date 2021/9/26 11:13
 * @Version 1.0
 **/
public class FunctionTest {
    public static void main(String[] args) {
        ArrayList<Object> objects = new ArrayList<>();
        objects.add("1");
        objects.add("2");
        List<Object> collect = objects.stream().sorted((a1, a2) -> {
            return a1.equals(a2) ? 0 : 1;
        }).collect(Collectors.toList());
        objects.stream().map(a -> {
            System.out.println(a);
            return "a";
        }).collect(Collectors.toList());


        MyClass myClass = new MyClass();
        FunctionClass functionClass = new FunctionClass();
        String s = functionClass.doGreet(p -> myClass.say(p, 111), "wangwu");
        System.out.println("main:" + s);

        String Suppliers = functionClass.doGreet(() -> myClass.say("wangwu", 111));
        System.out.println("main Suppliers:" + Suppliers);
    }
}

class MyClass {
    public String say(String name, Integer greeting) {
        return name + " greeting: " + greeting;
    }
}

class FunctionClass {
    public String doGreet(Function<String, String> sayFunction, String name) {
        System.out.println("do Greet:");
        return sayFunction.apply(name);
    }

    public String doGreet(Supplier<String> supplier) {
        System.out.println("do Supplier Greet:");
        return supplier.get();
    }
}